package com.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.mapper.Sms_Home_Subject_Mapper;
import com.shop.pojo.sms.Sms_Home_Subject;
import com.shop.service.Sms_Home_Subject_Service;
import com.shop.utils.LayuiUtils;
import com.shop.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 专题列表-李贝贝
 */
@Service
public class Sms_Home_Subject_ServiceImpl implements Sms_Home_Subject_Service {

    @Autowired
    private Sms_Home_Subject_Mapper sms_home_subject_mapper;

    /**
     * 显示所有
     * @param pages
     * @param sms_home_subject
     * @return
     */
    @Override
    public LayuiUtils<Sms_Home_Subject> find_admin_all_home_subject(Page<Sms_Home_Subject> pages, Sms_Home_Subject sms_home_subject) {
        LayuiUtils<Sms_Home_Subject> layuis = new LayuiUtils<>();
        QueryWrapper<Sms_Home_Subject> query = new QueryWrapper<>();
        if (sms_home_subject.getName() != null){
            query.like("name",sms_home_subject.getName());
        }
        Page<Sms_Home_Subject> sms_home_subjectPage = sms_home_subject_mapper.selectPage(pages,query);
        layuis.setCount(sms_home_subjectPage.getTotal());
        layuis.setData(sms_home_subjectPage.getRecords());
        return layuis;
    }

    /**
     * 新增
     * @param sms_home_subject
     * @return
     */
    @Override
    public R insert_admin_home_subject(Sms_Home_Subject sms_home_subject) {
        int insert = sms_home_subject_mapper.insert(sms_home_subject);
        if(insert > 0){
            return R.success();
        }
        return R.error(500,"添加失败");
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public R delete_admin_home_subject(List<Long> id) {
        int delete = sms_home_subject_mapper.deleteBatchIds(id);
        if(delete > 0){
            return R.success();
        }
        return R.error(500,"删除失败");
    }

    /**
     * 修改
     * @param sms_home_subject
     * @return
     */
    @Override
    public R update_admin_home_subject(Sms_Home_Subject sms_home_subject) {
        int update = sms_home_subject_mapper.updateById(sms_home_subject);
        if(update > 0){
            return R.success();
        }
        return R.error(500,"修改失败");
    }
}
